﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Manager;
using Model;
using ExtAspNet;
using Manager.CustomerHelper;
namespace HealthSystem.sysAdmin
{
    public partial class Permit : BasePage
    {
        HW_SchoolManager manager = new HW_SchoolManager();
        public override ModuleType Module
        {
            get
            {
                return ModuleType.SchoolManager;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //choosebt.OnClientClick = Window1.GetSaveStateReference(TextBox2.ClientID)
                //   + Window1.GetShowReference("~/ChooseOrg.aspx");
                //btnClose.OnClientClick = ActiveWindow.GetConfirmHidePostBackReference();
                string id = Request["id"].ToString();
                HW_School school = manager.GetById(id);
                if (school.Permit.HasValue)
                {
                    if (school.Permit.Value)
                    {
                        Permitbt.Text = "取消授权";
                        Permitbt.Icon = ExtAspNet.Icon.SystemClose;
                    }
                    else
                    {
                        Permitbt.Text = "授权";
                        Permitbt.Icon = ExtAspNet.Icon.Accept;
                    }
                }
                else
                {
                    Permitbt.Text = "授权";
                    Permitbt.Icon = ExtAspNet.Icon.Accept;
                }
                ////bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
                ////if (exist)
                ////{
                //Bind(school);
                ////}
            }
        }
        //public void Bind(HW_School school)
        //{
        //    this.name.Text = school.Name;
        //    this.id.Text = school.SchoollCode;

        //    LinkMan.Text = school.LinkMan;
        //    MobilePhone.Text = school.MobilePhone;
        //    OfficePhone.Text = school.OfficePhone;
        //    Address.Text = school.Address;
        //    SchoolType.Text = school.SchoolType;
        //    Email.Text = school.Email;
        //    // manager.ModHW_School(school);
        //}
        //protected void Save_Click(object sender, EventArgs e)
        //{
        //    string id = Request["id"].ToString();
        //    HW_School school = manager.GetById(id);
        //    bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
        //    if (exist)
        //    {
        //        school.Name = this.name.Text;
        //        school.LinkMan = LinkMan.Text;
        //        school.MobilePhone = MobilePhone.Text;
        //        school.OfficePhone = OfficePhone.Text;
        //        school.Address = Address.Text;
        //        school.SchoolType = SchoolType.Text;
        //        school.Email = Email.Text;
        //        manager.ModHW_School(school);
        //        PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
        //    }
        //    else
        //    {
        //        Alert.Show("您没有权限修改该学校");
        //    }
        //}
        protected void Permitbt_Click(object sender, EventArgs e)
        {
            try
            {
                HW_School school = manager.GetById(Request["id"].ToString());
                bool exist = DistrictCache.CheckExist(CustomerProfile.DistrictId, school.DistrictCode);
                if (exist)
                {
                    if (school.Permit.HasValue)
                    {
                        if (school.Permit.Value)
                        {
                            school.Permit = false;
                        }
                        else
                        {
                            school.Permit = true;
                        }
                    }
                    else
                    {
                        school.Permit = true;
                    }
                    manager.Permit(school);
                    

                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
                else
                {
                    Alert.Show("您没有权限给该用户授权");
                }
            }
            catch
            {
                Alert.Show("授权出错！");
            }
        }
    }
}